<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Redis;
use App\Models\User;
use Illuminate\Support\Facades\Log;
class AdminController extends Controller{
	public $_W;
	public $_GPC;
	
	function __construct(){
		$this->_W = $this->_GPC = array();
		$this->_W['siteroot'] = $_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST']."/";
		$this->_W['isajax'] = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
		$this->_GPC = array_merge($_GET, $_POST);
	}
	
	public function index(){
		$_W = $this->_W;
		$_GPC = $this->_GPC;
		if (isset($_GPC['a'])){
			$action = $_GPC['a'];
			if (empty($action)) $action = 'model';
		}else $action = 'model';
		if (!isset($_GPC['op'])) $_GPC['op'] = '';
		$viewdata = array('action'=>$action,'_COOKIE'=>$_COOKIE,'_W'=>$_W);
		$userModel = new User();
		$user = [];
		if ($action != 'login' && $action != 'logout'){
			$user = $userModel->getUserInfo();
		}
		include_once "admin/{$action}.php";
		$viewdata['_GPC'] = $_GPC;
		$viewdata['user'] = $user;
		if (!isset($_COOKIE['papersystem_site_theme'])) $_COOKIE['papersystem_site_theme'] = $_COOKIE['papersystem_logo_bg'] = $_COOKIE['papersystem_header_bg'] = $_COOKIE['papersystem_sidebar_bg'] = 'default';
		echo view('admin.header',['user'=>$user,'action'=>$action,'_COOKIE'=>$_COOKIE]);
		return view("admin.{$action}",$viewdata);
	}
}